package com.fengpb.friday.conductor.dao.mysql;

import com.fengpb.friday.conductor.common.metadata.workflow.WorkflowDef;
import com.fengpb.friday.conductor.dao.MetadataDAO;
import com.fengpb.friday.conductor.dao.mapper.MetadataMapper;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@ConditionalOnProperty(name = "conductor.persistence", havingValue = "mysql", matchIfMissing = true)
public class MysqlMetadataDAO implements MetadataDAO {

    private final MetadataMapper mapper;

    public MysqlMetadataDAO(MetadataMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public List<WorkflowDef> getAllWorkflowDef() {
        return mapper.getAllWorkflowDef();
    }

    @Override
    public WorkflowDef getWorkflowDef(String name, int version) {
        return mapper.getWorkflowDef(name, version);
    }

    @Override
    public Integer updateWorkflowDef(WorkflowDef def, int latestVersion, String json_data) {
        return mapper.updateWorkflowDef(def, latestVersion, json_data);
    }

    @Override
    public Integer registerWorkflowDef(WorkflowDef def, int latestVersion, String json_data) {
        return mapper.registerWorkflowDef(def, latestVersion, json_data);
    }
}
